
function add_new_category(tournament_id){
	jQuery.post(BASE_URI+'admin/dataman/weekly_prize/add_category',{tournament_id:tournament_id},function(res){
		jQuery('#dialog').html(res);
		jQuery('#dialog').dialog(
			{
				 width: 650,
				 resizable: false,
				 height:300,
				 title: 'Add Prize Category' 
			}
		);
	});
}

function editCategory(cat_id,tournament_id){
	jQuery('#loader_image_manage_'+cat_id).show();
	jQuery.post(BASE_URI+'admin/dataman/weekly_prize/add_category',{cat_id:cat_id,tournament_id:tournament_id},function(res){
		jQuery('#dialog').html(res);
		jQuery('#dialog').dialog(
			{
				 width: 650,
				 resizable: false,
				 height:300,
				 title: 'Edit Prize Category' 
			}
		);
		jQuery('#loader_image_manage_'+cat_id).hide();
	});
}

function changeEnablePrizeCate(cat_id){
	jQuery('#loader_image_enable_'+cat_id).show();
	jQuery.post(BASE_URI+'admin/dataman/weekly_prize/changeEnablePrizeCate',{cat_id:cat_id},function(res){
		reload();
	});
}

function openPrizeManage(cat_id){
	jQuery('#loader_image_title_'+cat_id).show();
	jQuery.post(BASE_URI+'admin/dataman/weekly_prize/prize_view_manage',{cat_id:cat_id},function(res){
		jQuery('#dialog').html(res);
		jQuery('#dialog').dialog(
			{
				 width: 900,
				 resizable: false,
				 height:600,
				 title: 'Prize Manage' 
			}
		);
		jQuery('#loader_image_title_'+cat_id).hide();
	});
}

function add_new_prize(cat_id){
	jQuery.post(BASE_URI+'admin/dataman/weekly_prize/add_edit_prize',{cat_id:cat_id},function(res){
		jQuery('#dialog2').html(res);
		jQuery('#dialog2').dialog(
			{
				 width: 650,
				 resizable: false,
				 height:300,
				 title: 'Add New Prize' 
			}
		);
	});	
}

function prize_edit(id,cat_id){
	jQuery('#loader_image_prize_'+id).show();
	jQuery.post(BASE_URI+'admin/dataman/weekly_prize/add_edit_prize',{cat_id:cat_id,id:id},function(res){
		jQuery('#dialog2').html(res);
		jQuery('#dialog2').dialog(
			{
				 width: 650,
				 resizable: false,
				 height:300,
				 title: 'Edit New Prize' 
			}
		);
		jQuery('#loader_image_prize_'+id).hide();
	});	
}

function prize_delete(id,cat_id){
	jQuery('#loader_image_prize_'+id).show();
	jQuery.post(BASE_URI+'admin/dataman/weekly_prize/prize_delete',{id:id},function(res){
		openPrizeManage(cat_id);
	});
}

function finishWeeklyPrize(cat_id){
	jQuery('#loader_image_manage_'+cat_id).show();
	jQuery.post(BASE_URI+'admin/dataman/weekly_prize/finishWeeklyPrize',{cat_id:cat_id},function(res){
		reload();
	});
}

jQuery(document).ready(function() {
	var options = { 
		beforeSubmit:beforeSubmit,   
		success:afterSubmit
	};	
	var options2 = { 
		beforeSubmit:beforeSubmit,   
		success:afterSubmitPrize
	};	
	
	jQuery("#category_submit").live("submit",function(e){
		e.preventDefault(); // <-- important
		jQuery(this).ajaxSubmit(options);
		return false;
	});	
	
	jQuery("#prize_submit").live("submit",function(e){
		e.preventDefault(); // <-- important
		jQuery(this).ajaxSubmit(options2);
		return false;
	});	 
	
});

function afterSubmitPrize(responseText, statusText, xhr, $form){
	jQuery('#loader_image').hide();
	if(isNaturalNumber(responseText)){
		openPrizeManage(responseText); //cat_id
		jQuery('#dialog2').dialog('close');
	}else{
		alert(responseText);
	}
}

function beforeSubmit(formData, jqForm, options){
	jQuery('#loader_image').show();
	return true;
}

function afterSubmit(responseText, statusText, xhr, $form){
	jQuery('#loader_image').hide();
	if(responseText == 'ok'){
		reload();
	}else{
		alert(responseText);
	}
}

jQuery(function() {
	jQuery("#start_time_btn").live('click',function(){
		jQuery('.DynarchCalendar-topCont').css({top:100,width:60});
		Calendar.setup({
			inputField : "starttime",
			trigger    : "start_time_btn",
			onSelect   : function() { this.hide() },
			showTime   : 24,
			dateFormat : "%Y-%m-%d %I:%M"
		});
	});
	jQuery("#end_time_btn").live('click',function(){
		jQuery('.DynarchCalendar-topCont').css({top:100,width:60});
		Calendar.setup({
			inputField : "endtime",
			trigger    : "end_time_btn",
			onSelect   : function() { this.hide() },
			showTime   : 24,
			dateFormat : "%Y-%m-%d %I:%M"
		});
	});
	jQuery("#shipping_date_btn").live('click',function(){
		jQuery('.DynarchCalendar-topCont').css({top:100,width:60});
		Calendar.setup({
			inputField : "shipping_date",
			trigger    : "shipping_date_btn",
			onSelect   : function() { this.hide() },
			showTime   : 24,
			dateFormat : "%Y-%m-%d"
		});
	});
	
});